# Maintainer: Leonardo Arena <rnalrd@alpinelinux.org>
pkgname=virt-manager
pkgver=4.1.0
pkgrel=3
pkgdesc="GUI for managing virtual machines"
url="https://virt-manager.org/"
arch="noarch !s390x !riscv64" # spice-gtk
license="GPL-2.0-or-later"
depends="
	python3
	$pkgname-common
	spice-gtk
	vte3
	py3-cairo
	gtk-vnc>=0.5.2-r2
	gtksourceview4
	qemu-img
	"
_common_deps="
	libvirt-glib
	py3-libxml2
	py3-libvirt
	py3-gobject3
	py3-requests
	libosinfo
	"
makedepends="glib-dev py3-docutils py3-setuptools"
checkdepends="
	xorriso
	libosinfo-dev
	py3-gobject3
	py3-libvirt
	py3-libxml2
	py3-pytest
	py3-requests
	"
subpackages="
	$pkgname-doc
	$pkgname-lang
	$pkgname-pyc
	$pkgname-common
	virt-install:virt_install
	$pkgname-bash-completion
	"
source="
	https://releases.pagure.org/virt-manager/virt-manager-$pkgver.tar.gz
	fix-latest-libvirt-xml-output.patch
	"

# secfixes:
#   2.2.1-r0:
#     - CVE-2019-10183

build() {
	python3 setup.py build
}

check() {
	_skipped_tests="
		not testAlterCpuMode
		and not testCLI0004virt_install_many_devices
		and not testCLI0020virt_install_cpu_rhel7_default
		and not testCLI0388virt_xml_edit_cpu_host_copy
		and not testCLI0402virt_xml_edit_simple_features
		and not testCLI0454virt_xml_add_host_device
		and not testCLI0057virt_install_osinfo_url
		and not testCLI0079virt_install_osinfo_url_with_disk
		and not testCLI0114virt_install_osinfo_url_unattended
		and not testCLI0115virt_install_osinfo_unattended_treeapis
	"

	python3 -m pytest -k "$(echo $_skipped_tests | tr -d '\n')"
}

package() {
	python3 setup.py --no-update-icon-cache --no-compile-schemas install --root "$pkgdir"
	python3 -m compileall "$pkgdir/usr/share/virt-manager"
}

common() {
	pkgdesc="Common files used by virt-manager and virt-install"
	depends="$_common_deps"
	mkdir -p "$subpkgdir"/usr/share/virt-manager "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/share/virt-manager/virtinst \
		"$subpkgdir"/usr/share/virt-manager
}

virt_install() {
	pkgdesc="Utilities for installing virtual machines"
	depends="$pkgname-common=$pkgver-r$pkgrel"
	mkdir -p "$subpkgdir"/usr/share/virt-manager "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/virt-install \
		"$pkgdir"/usr/bin/virt-clone \
		"$subpkgdir"/usr/bin/
}

pyc() {
	default_pyc
	local IFS='
'
	amove $(find usr/share/virt-manager/virtManager -type d -name __pycache__)
}

sha512sums="
725cb5bcbaebaafae417f95deffb4243ccdad769668cba6e1235f4607e2b29dbd099d2a9a3885981158f53ea854dd71cc29ed9d7557b2791161c13d34f2ef883  virt-manager-4.1.0.tar.gz
3106c7d3d91db6c7fa3208a13869c5a84bb636a261939acd3be0a59ce7196dfa6102ec97372d762d8143cef4a1d0ef1c37f4a107c3826c23ff2ed22c6d57f914  fix-latest-libvirt-xml-output.patch
"
